package com.dao.qsl;

import com.util.qsl.Dbutil;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

@Repository
public class HdXxAdd {
      public Boolean add(String hdmc,String xqmc ,String kssj ,String jssj){

	  Dbutil d=new Dbutil();

	  int xqid=xqid(xqmc);

	  Connection c=null;
	  try {
	        c=d.getConnection();
	        String sql="INSERT into community VALUES(null,?,?,?,'进行中',0,?)";

	        PreparedStatement pr=c.prepareStatement(sql);

	        pr.setString(1,hdmc);
	        pr.setString(2,kssj);
	        pr.setString(3,jssj);
	        pr.setInt(4,xqid);

	        int i=pr.executeUpdate();

	        if (i>0){
		    return true;
	        }else {
		    return false;
	        }
	  }catch (Exception e){
	        e.printStackTrace();
	  }
		return false;
      }

//      获取小区编号
      public static int xqid(String xqmc){

	  Dbutil d=new Dbutil();

	  Connection c=null;

	  int xqid=0;
	  try {
	        c=d.getConnection();
	        String sql="SELECT vid from village where vname=?";

	        PreparedStatement pr=c.prepareStatement(sql);

	        pr.setString(1,xqmc);

	        ResultSet rs=pr.executeQuery();

	        if (rs.next()) {
		    xqid=rs.getInt("vid");
	        }
	  }catch (Exception e) {
	        e.printStackTrace();
	  }
	return xqid;
      }
}
